package com.kaver.job.springboot.starter.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.kaver.job.core.djob.DJobService;
import com.kaver.job.core.djob.DJobServiceImpl;
import com.kaver.job.core.djob.DynamicJob;
import com.kaver.job.core.executor.impl.JobSpringExecutor;

/**
 * kaver-job config
 *
 * @author ROC 
 */
@Configuration
public class JobConfig {
    private Logger logger = LoggerFactory.getLogger(JobConfig.class);

    @Value("${kaver.job.admin.addresses}")
    private String adminAddresses;

    @Value("${kaver.job.executor.appname}")
    private String appName;

    @Value("${kaver.job.executor.ip:}")
    private String ip;

    @Value("${kaver.job.executor.port}")
    private int port;

    @Value("${kaver.job.accessToken:}")
    private String accessToken;

    @Value("${kaver.job.executor.logpath}")
    private String logPath;

    @Value("${kaver.job.executor.logretentiondays}")
    private int logRetentionDays;

    @Value("${kaver.job.executor.address:}")
    private String address;
    
    @Bean
    public JobSpringExecutor kaverJobExecutor() {
        logger.info(">>>>>>>>>>> kaver-job config init.");
        JobSpringExecutor jobSpringExecutor = new JobSpringExecutor();
        jobSpringExecutor.setAdminAddresses(adminAddresses);
        jobSpringExecutor.setAppname(appName);
        jobSpringExecutor.setAddress(address);
        jobSpringExecutor.setIp(ip);
        jobSpringExecutor.setPort(port);
        jobSpringExecutor.setAccessToken(accessToken);
        jobSpringExecutor.setLogPath(logPath);
        jobSpringExecutor.setLogRetentionDays(logRetentionDays);

        return jobSpringExecutor;
    }
    @Bean
    public DynamicJob getDynamicJob() {
        return new DynamicJob();
    }
    
    @Bean
    public DJobService getDJobService() {
        return new DJobServiceImpl();
    }
}